package cn.factorybox.item.filter;

import cn.factorybox.item.shiro.JWTToken;
import org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter;
import org.springframework.stereotype.Component;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

/**
 * @author flypig
 * @version 1.0
 * @date 2020-04-19 21:07
 */
public class JWTFilter extends BasicHttpAuthenticationFilter {

    // 拦截header带token的请求
    @Override
    protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
        // 判断请求的header是否带有"header"
        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
        String token = httpServletRequest.getHeader("token");
        JWTToken jwtToken = new JWTToken(token);
        System.out.println("拦截成功");
        return true;
    }

}
